﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//*
using System.Windows.Media;
using System.Windows.Media.Imaging;
//*/
namespace UI
{
    class brushFactory
    {
        /*
        On représente les informations sur une case par les bits d'un entier dont voici la signification :
        b0 : est un plaine
        b1 : est une montagne
        b2 : est une désert
        b15 : a un décorateur fer
        b16 : a un décorateur fruit
        */
        static Dictionary<int, ImageBrush> brushes = new Dictionary<int, ImageBrush>();
        static System.Windows.Media.Brush fillDefault = System.Windows.Media.Brushes.White;

        public static void reInit()
        {
            brushes = new Dictionary<int, ImageBrush>();
        }
        public static System.Windows.Media.Brush get(int caseInfos)
        {

            if (brushes.ContainsKey(caseInfos))
                return brushes[caseInfos];

            if (caseInfos == 1337)
            {
                System.Drawing.Bitmap img = Properties.Resources.ville;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                new ImageBrush(b);
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];
            }
            if ((caseInfos & (1 << 0)) != 0)
            {
                System.Drawing.Bitmap img = Properties.Resources.plaine;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                new ImageBrush( b );
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];
            }
            if ((caseInfos & (1 << 1)) != 0)
            {
                System.Drawing.Bitmap img = Properties.Resources.montagne;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];
            }
            if ((caseInfos & (1 << 2)) != 0)
            {
                System.Drawing.Bitmap img = Properties.Resources.desert;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];
                
            }
            if ((caseInfos & (1 << 15)) != 0)
            {
                System.Drawing.Bitmap img = Properties.Resources.fer;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];

            } 
            if ((caseInfos & (1 << 16)) != 0)
            {
                System.Drawing.Bitmap img = Properties.Resources.fruit;
                BitmapSource b = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(img.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                brushes.Add(caseInfos, new ImageBrush(b));
                return brushes[caseInfos];

            }

            return null;
        }
    }
}